package com.asia5b.a5bmall.same.adapter

import android.text.TextUtils
import android.widget.ImageView
import android.widget.TextView
import com.asia5b.a5bmall.resource.ResString
import com.asia5b.a5bmall.same.R
import com.asia5b.a5mall.middleware.model.home.CategoryModel
import com.asia5b.a5mall.middleware.model.shop.ApplyShopResModel
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder

/**
 * Created by zhangyuncai on 2020/6/29.
 */
class SelectCateAdapter(var list: ArrayList<CategoryModel>) :
        BaseQuickAdapter<CategoryModel, BaseViewHolder>(R.layout.item_selectbase_adapter, list) {
    override fun convert(helper: BaseViewHolder, item: CategoryModel) {
        helper.setIsRecyclable(false)

        val tv_selectbase_name = helper.getView<TextView>(R.id.tv_selectbase_name)
        val iv_selectbase_check = helper.getView<ImageView>(R.id.iv_selectbase_check)

        tv_selectbase_name.text = item.showName()
        iv_selectbase_check.isSelected = item.checked

        helper.itemView.setOnClickListener {
            item.checked = !item.checked
            if (TextUtils.equals(item.showName(), ResString.get(R.string.全选))) {
                for (categoryModel in list) {
                    categoryModel.checked = item.checked
                }
            }
            notifyDataSetChanged()
        }
    }
}